//
//  SISSRegistrationViewController.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/13.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSRegistrationViewController.h"
#import "SISSNavigationController.h"
#import "SISSHouseResourceEnrollViewController.h"
#import "SISSPassengerResourceEnrollViewController.h"
#import "SISSHouseResourceCooperationViewController.h"
#import "SISSPassengerResourceCooperationViewController.h"
#import "AppDelegate.h"

@interface SISSRegistrationViewController ()

@end

@implementation SISSRegistrationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
}



/**
 各功能按钮点击事件

 @param button 点击按钮
 */
- (void)buttonActoion:(UIButton *)button {
    
    // 回调block
    if (self.buttonClickBlock) {
        self.buttonClickBlock();
    }
    
    // 跳转不同的控制器
    SISSNavigationController *navc;
    switch (button.tag) {
        case 0: {
            SISSHouseResourceEnrollViewController *vc = [[SISSHouseResourceEnrollViewController alloc] init];
            vc.title = @"房源登记";
            vc.isRegistration = YES;
            navc = [[SISSNavigationController alloc] initWithRootViewController:vc];
        }
            break;
        case 1: {
            SISSPassengerResourceEnrollViewController *vc = [[SISSPassengerResourceEnrollViewController alloc] init];
            vc.title = @"客源登记";
            vc.isRegistration = YES;
            navc = [[SISSNavigationController alloc] initWithRootViewController:vc];
        }
            break;
        case 2: {
            SISSHouseResourceCooperationViewController *vc = [[SISSHouseResourceCooperationViewController alloc] init];
            vc.title = @"房源合作";
            navc = [[SISSNavigationController alloc] initWithRootViewController:vc];
        }
            break;
        case 3: {
            SISSPassengerResourceCooperationViewController *vc = [[SISSPassengerResourceCooperationViewController alloc] init];
            vc.title = @"客源合作";
            navc = [[SISSNavigationController alloc] initWithRootViewController:vc];
        }
            break;
        default:
            break;
    }
    
   
    AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    navc.modalPresentationStyle = UIModalPresentationFullScreen;
    [delegate.window.rootViewController presentViewController:navc animated:YES completion:nil];
    
//    [self presentViewController:navc animated:YES completion:nil]; //Presenting view controllers on detached view controllers is discouraged <SISSRegistrationViewController: 0x7fb1d05267a0>.
    
}


/**
 点底部取消按钮的点击事件
 */
- (void)cancellButtonClick:(UIButton *)button {
    
    if (self.buttonClickBlock) {
        self.buttonClickBlock();
    }
}

#pragma mark - 设置UI
- (void)setupSubviews {
    [super setupSubviews];
    
    UIView *view = [[UIView alloc] init];
    [self.view addSubview:view];
    CGSize size = CGSizeMake(SCREEN_WIDTH - 40, 80);
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(self.view).offset(SCREEN_HEIGHT * 0.25);
        make.size.mas_equalTo(size);
    }];
    
    NSArray *imageNames = @[@"1", @"2", @"3", @"4"];
    NSArray *titleNames = @[@"房源登录", @"客源登记", @"房源合作", @"客源合作"];
    
    // 循环创建四个按钮
    for (int i = 0; i < 4; i ++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        // 创建属性文本对象
        NSAttributedString *attrStr = [NSAttributedString yyr_imageTextWithImage:[UIImage imageNamed:imageNames[i]] imageWH:60 title:titleNames[i] fontSize:11 titleColor:[UIColor yyr_colorWithHex:0x334A60] spacing:8];
        // 设置button的属性文本
        [button setAttributedTitle:attrStr forState:UIControlStateNormal];
        button.titleLabel.numberOfLines = 0;
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [view addSubview:button];
        [button sizeToFit];
        button.tag = i;
        CGFloat margin = ((56 + 33) / 375.0) * SCREEN_WIDTH;
        button.frame = CGRectMake(i * margin, 10, 56, 56);
        
        [button addTarget:self action:@selector(buttonActoion:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    // 底部视图
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 47, SCREEN_WIDTH, 47)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bottomView];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [bottomView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(bottomView);
        make.height.mas_equalTo(1);
    }];
    
    // 底部取消按钮
    UIButton *deleteButton = [[UIButton alloc] init];
    [deleteButton setImage:[UIImage imageNamed:@"guanbi"] forState:UIControlStateNormal];
    [deleteButton sizeToFit];
    [deleteButton addTarget:self action:@selector(cancellButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [bottomView addSubview:deleteButton];
    [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(bottomView);
        
    }];

}

@end
